import $axios from '@/sever'
import { Root } from '@/types'

// 获取所有的角色和权限
export const getRole = async () => {
  return await $axios.get('/permissions/getRole')
}
// 修改用户账号是否启用
export const updateUser = async (id: string, status: boolean) => {
  return await $axios.put('/permissions/updateStatus', { id, status })
}
// 获取品牌:进行分页、搜索
export const getBrand = async (
  pageNum: number,
  pageSize: number,
  searchBrand: string
) => {
  return await $axios.get(
    `/getBrand?pageNum=${pageNum}&pageSize=${pageSize}&search=${searchBrand}`
  )
}
// 获取单个分类数据
export const getCommodityClassifyId = async (id: number) => {
  return await $axios.get(`/commodity/categoryDetail?id=${id}`)
}

// 获取商品单个属性
export const getCommodityAttributeId = async (id: number) => {
  return await $axios.get(`/commodity/productAttribute?id=${id}`)
}

// 获取商品参数
export const getCommodityParameter = async (id: number) => {
  return await $axios.get(`/commodity/parameter?id=${id}`)
}

// 修改单个的品牌数据
export const putBrandId = async (obj: any) => {
  return await $axios.put('/putBrandId', obj)
}
// 获取商品类型
export const getCommodityType = async (pageNum: number, pageSize: number) => {
  return await $axios.get(
    `/commodity/commodityType?pageNum=${pageNum}&pageSize=${pageSize}`
  )
}

// 获取商品分类
export const getcommodityClassify = async (
  pageNum: number,
  pageSize: number
) => {
  return await $axios.get(
    `/commodity/commodityClassify?pageNum=${pageNum}&pageSize=${pageSize}`
  )
}

// 获取商品分类检索
export const getcommodityClassifySearch = async () => {
  return await $axios.get(`/commodity/commodityClassifySearch`)
}

// 获取品牌的检索
export const getBrandSearch = async () => {
  return await $axios.get(`/commodity/brandSearch`)
}

// 获取商品的列表
export const getCommodityList = async (
  pageNum: number,
  pageSize: number,
  searchValue?: Record<string, any>
) => {
  const searchQuery = new URLSearchParams(searchValue).toString()
  return await $axios.get(
    `/commodity/commodityList?pageNum=${pageNum}&pageSize=${pageSize}&${searchQuery}`
  )
}

// 对于sku数据的获取
export const getSkuList = async (
  id: number,
  productAttributeCategoryId: number
) => {
  return await $axios.get(
    `/commodity/sku?id=${id}&productAttributeCategoryId=${productAttributeCategoryId}`
  )
}

// 公共删除数据
export const delData = async (id: string, path: string) => {
  return await $axios.delete(`/${path}?id=${id}`)
}
//陈浩-表单获取
export const getOrderList = async (
  event: number | undefined,
  status: number | undefined,
  SubmitTime: string | undefined,
  sourceType: number | undefined,
  orderType: number | undefined,
  number: string | undefined,
  receiverName: string | undefined
) => {
  return await $axios.get(
    '/order/getorder?page=' +
      event +
      '&status=' +
      status +
      '&SubmitTime=' +
      SubmitTime +
      '&sourceType=' +
      sourceType +
      '&orderType=' +
      orderType +
      '&number=' +
      number +
      '&receiverName=' +
      receiverName
  )
}
//陈浩状态修改
export const orderupdate = async (obj: any) => {
  return await $axios.put('/order/orderupdate', obj)
}
export const orderdateil = async (id: string) => {
  return await $axios.get('/order/orderdateil?id=' + id)
}
export const ordercancel = async (id: string | undefined) => {
  return await $axios.put('/order/ordercancel', { id: id })
}
export const historyadd = async (obj: object) => {
  return await $axios.put('/order/historyadd', obj)
}
export const returns = async (page: number, pageSize: number, obj: object) => {
  return await $axios.get(
    '/order/returns?page=' +
      page +
      '&pageSize=' +
      pageSize +
      '&obj=' +
      JSON.stringify(obj)
  )
}
export const reDel = async (list: any) => {
  return await $axios.post('/order/rdel', { obj: list })
}
export const returnsdetaile = async (id: string | null | undefined) => {
  return await $axios.get('/order/returnsdetaile?id=' + id)
}
export const updatePermissions = async (
  id: string,
  PermissionsIds: string[]
) => {
  return await $axios.put('/permissions/updatePermissions', {
    id,
    PermissionsIds
  })
}

// 获取买家列表
export const getCustomList = async (pageNum: number, pageSize: number) => {
  return await $axios.get(
    `/user/custom-list?pageNum=${pageNum}&pageSize=${pageSize}`
  )
}
export const rts = async (
  id: string | undefined,
  status: number | undefined
) => {
  return await $axios.put('/order/rts', { id, status })
}
// 获取图表数据
export const getOrders = async () => {
  return await $axios.get('/permissions/getOrders')
}
// 修改用户权限
export const updatePermissionsUser = async (id: string, MenuList: Root) => {
  return (await $axios.post('/permissions/updateRole', { id, MenuList })).data
}
